package com.example.timer.config;

import com.example.timer.executor.JobExecutor;
import com.example.timer.test.SimpleJobTest;

import java.util.Collections;
import java.util.logging.Logger;

/**
 * @author daiguojun
 */
public class JobConfig {
    private static Logger logger = Logger.getLogger(JobConfig.class.getName());


    private static JobConfig instance = new JobConfig();
    public static JobConfig getInstance() {
        return instance;
    }


    public static JobExecutor jobExecutor = null;

    /**
     * init
     */
    public void initJobExecutor() {

        // init executor
        jobExecutor = new JobExecutor();
        // registry job bean  此处需要 把需要调度的方法都放过来
        jobExecutor.setXxlJobBeanList(Collections.singletonList(new SimpleJobTest()));

        // start executor
        try {
            jobExecutor.start();
        } catch (Exception e) {
            logger.severe(e.getMessage());
        }
    }

    /**
     * destroy
     */
    public void destroyJobExecutor() {
        if (jobExecutor != null) {
            jobExecutor.destroy();
        }
    }

}
